package com.zzh.myapplication.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import net.icarplus.car.R;
import net.icarplus.car.bean.CarImageBean;
import net.icarplus.car.bean.CarInfo;
import net.icarplus.car.bean.CarPriceBean;

import java.util.List;

/**
 * 项目名称：icarplus-car-android
 * 类描述：
 * 创建人：Gophy
 * 创建时间：16/3/10 14:14
 * 修改人：Gophy
 * 修改时间：16/3/10 14:14
 * 修改备注：
 */

public class BookCarListAdapter extends BaseAdapter {

    private Context context;

    private LayoutInflater inflater;
    private List<CarInfo> bookCarList;

    public BookCarListAdapter(Context context, List<CarInfo> bookCarList) {
        super();
        inflater = LayoutInflater.from(context);
        this.context = context;
        this.bookCarList = bookCarList;
    }

    @Override
    public int getCount() {
        return bookCarList == null ? 0 : bookCarList.size();
    }

    @Override
    public Object getItem(int i) {
        return bookCarList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        if (viewHolder == null) {
            viewHolder = new ViewHolder();
            view = inflater.inflate(R.layout.item_car_list_book, null);
            viewHolder.carPic = (ImageView) view.findViewById(R.id.iv_car_name);
            viewHolder.bookCarName = (TextView)view.findViewById(R.id.tv_book_car_name);
            viewHolder.bookCarPrice = (TextView)view.findViewById(R.id.tv_book_car_money);
            viewHolder.bookCarType = (TextView)view.findViewById(R.id.tv_book_car_type);
            viewHolder.bookCarCompany = (TextView)view.findViewById(R.id.tv_book_car_company);

        } else {
            viewHolder = (ViewHolder) view.getTag();
        }

        CarInfo model = bookCarList.get(position);

        List<CarPriceBean> carPrice = model.priceList;
        List<CarImageBean> carImage = model.carImgList;


        for (int i = 0; carPrice != null && i < carPrice.size() && carImage != null && i < carImage.size(); i++) {
            CarPriceBean carPriceBean = carPrice.get(i);
            CarImageBean carImageBean = carImage.get(i);

            String price = carPriceBean.unitPrice;
            String[] unit = price.split("\\/");

            String gearBox = model.gearBox;

//
//        viewHolder.bookCarName.setText(model.getBookCarName());
//        viewHolder.bookCarPrice.setText(model.getBookCarPrice());
//        viewHolder.bookCarType.setText(model.getBookCarType());
//        viewHolder.bookCarCompany.setText(model.getBookCarCompany());
        }
        return view;
    }

    class ViewHolder {
        ImageView carPic;
        TextView bookCarName;
        TextView bookCarPrice;
        TextView bookCarType;
        TextView bookCarCompany;
    }
}
